package inabit.inabitcompiler.productions.rule.expressions;

import inabit.compiler.parser.grammar.NonTerminal;
import inabit.compiler.parser.grammar.Production;
import inabit.compiler.parser.grammar.Symbol;
import inabit.compiler.parser.grammar.Terminal;
import inabit.data.expression.Expression;
import inabit.inabitcompiler.lexical.InabitTokenClass;
import inabit.inabitcompiler.parser.InabitSemanticAction;

/**K -> not(E)*/
/**@author Rafael Rocha*/
public class K_Rule3 extends Production{
	private NonTerminal E;
	public K_Rule3() {
		super("K");
	}

	@Override
	protected Symbol[] production(final NonTerminal nonTerminal) {
		E = new NonTerminal("E");
		Symbol[] symbols = {
			new Terminal(InabitTokenClass.NOT),
			new Terminal(InabitTokenClass.OPEN_PARENTHESIS),
			E,
			new Terminal(InabitTokenClass.CLOSE_PARENTHESIS),
			new InabitSemanticAction(nonTerminal) {
				public void execute() {
					Expression exp = getExpression(E.code).negation();
					nonTerminal.code = addExpressionAndGetCode(exp);
				}
			}
		};
		return symbols;
	}
	
}